﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shop.Order.Repositories;
using Shop.Order.Models;
using PetaPoco;

namespace Shop.Order.Services
{
    /// <summary>
    /// 订单管理业务逻辑层
    /// </summary>
    public class OrderAccess
    {
        Repositories.OrderAccess dal = new Repositories.OrderAccess();
        #region 用户产生订单
        /// <summary>
        /// 生成子订单
        /// </summary>
        /// <param name="odinfo"></param>
        /// <returns></returns>
        public object CreateOrderDetail(OrderDetail odinfo)
        {
            return dal.CreateOrderDetail(odinfo);
        }
        /// <summary>
        /// 生成订单
        /// </summary>
        /// <param name="oinfo"></param>
        /// <returns></returns>
        public object CreateOrder(Models.Order oinfo)
        {
            return dal.CreateOrder(oinfo);
        }
        /// <summary>
        /// 获取订单号
        /// </summary>
        /// <returns></returns>
        public string GetOrderNumber()
        {
            return dal.GetOrderNumber();
        }
        #endregion

        #region 用户订单查询
        /// <summary>
        /// 根据用户ID获取用户订单信息
        /// </summary>
        /// <param name="Page">第几页</param>
        /// <param name="PageNum">每页多少行</param>
        /// <param name="UID"></param>
        /// <returns></returns>
        public Page<Models.AnyOrder> GetUserOInfo(long Page, long PageNum, int UID)
        {
            return dal.GetUserOInfo(Page,PageNum,UID);
        }
        /// <summary>
        /// 根据订单号获取订单详情
        /// </summary>
        /// <param name="OrderNumber"></param>
        /// <returns></returns>
        public IList<Models.AnyOrderDetail> GetUserODInfo(string OrderNumber)
        {
            return dal.GetUserODInfo(OrderNumber);
        }
        #endregion

        #region 管理员后台管理
        /// <summary>
        /// 后台获取订单信息
        /// </summary>
        /// <param name="Page">第几页</param>
        /// <param name="PageNum">每页多少条</param>
        /// <param name="IfPay">是否支付</param>
        /// <param name="Status">订单状态</param>
        /// <param name="Strart">开始时间</param>
        /// <param name="End">结束时间</param>
        /// <param name="SearchType">搜索类型</param>
        /// <param name="Search">搜索内容</param>
        /// <param name="order">排序方式</param>
        /// <returns></returns>
        public Page<Models.Order> GetOInfo(long Page, long PageNum, int IfPay, int Status, string Strart, string End, int SearchType, string Search, int order)
        {
            return dal.GetOInfo(Page,PageNum,IfPay,Status, Strart, End, SearchType, Search, order);
        }
        /// <summary>
        /// 根据订单号获取订单信息
        /// </summary>
        /// <param name="OrderNumber">订单号</param>
        /// <returns></returns>
        public Models.Order GetOInfoByOrderNumber(string OrderNumber)
        {
            return dal.GetOInfoByOrderNumber(OrderNumber);
        }
        /// <summary>
        /// 将订单状态改为已发货
        /// </summary>
        /// <param name="OrderNumber"></param>
        /// <returns></returns>
        public int Delivery(string OrderNumber, string CourierNumber,string CCode)
        {
            return dal.Delivery(OrderNumber, CourierNumber, CCode);
        }
        #endregion
    }
}
